package algotithm.weekendrace.leetcode224.test2;

import java.util.HashMap;

/**
 * @author zhouyanxiang
 * @Date 2021-01-2021/1/17-23:12
 */
public class Solution {

    public static void main(String[] args) {
        Solution solution = new Solution();
        int[] nums = {2,3,4,6,8,12};
        int tupleSameProduct = solution.tupleSameProduct(nums);
        System.out.println(tupleSameProduct);
    }


    public int tupleSameProduct(int[] nums) {
        int count = 0;
        HashMap<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < nums.length; i++) {
            for (int j = i+1; j < nums.length; j++) {
                int val = nums[i] * nums[j];
                map.put(val,map.getOrDefault(val,0)+1);
            }
        }
        for (int val : map.values()) {
            if (val >= 2) {
                count += val * (val - 1) / 2;
            }
        }
        return count*8;
    }

}
